import re

from common.BasePages import BasePage


class ConfigurationTemplate(BasePage):
    # 组态模板
    def configuration_url(self):
        self.goto_url("visualizationCenter/configTempManagement")

    def create_configuration_template(self):
        self.page.get_by_role("button", name="  新增").click()
        self.page.get_by_role("textbox", name="请输入组态模板名称").click()
        self.page.get_by_role("textbox", name="请输入组态模板名称").fill("张院龙组态模板")
        self.page.get_by_role("button", name="确 定").click()
        self.assert_alert_content("添加组态成功")

    def edit_configuration_template_name(self):
        self.page.locator("div").filter(has_text=re.compile(r"^系统张院龙组态模板$")).locator("i").click()
        self.page.get_by_role("textbox", name="请输入组态模板名称").click()
        self.page.get_by_role("textbox", name="请输入组态模板名称").fill("张院龙组态模板编辑")
        self.page.get_by_role("button", name="确 定").click()
        self.assert_alert_content("修改组态成功")

    def configuration_template_copy(self):
        self.page.locator(".el-col > div:nth-child(3) > button:nth-child(2)").first.click()
        self.page.get_by_role("button", name="确定").click()

    def delete_configuration_template(self):
        self.page.get_by_role("button", name="  删除").first.click()
        self.page.get_by_role("button", name="确定").click()
        self.page.get_by_role("button", name="  删除").click()
        self.page.get_by_role("button", name="确定").click()
        self.assert_alert_content("删除成功!")
